layui.use(['form', 'layer', 'table', 'laydate', 'dropdown'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        table = layui.table,
        dropdown = layui.dropdown;

    //左侧菜单点击事件，其中 docDemoMenu1 对应的是菜单结构上的 id 指
    dropdown.on('click(docDemoMenu1)', function (options) {
        var othis = $(this); //当前菜单列表的 DOM 对象
        console.log(options); //菜单列表的 lay-options 中的参数
        switch (options.id) {
            case 1:
                window.location.href = "query01.html";
                break;
            case 2:
                window.location.href = "query02.html";
                break;
            case 3:
                window.location.href = "query03.html";
                break;
            case 4:
                window.location.href = "query04.html";
                break;
            case 5:
                window.location.href = "query05.html";
                break;
        }
    });

    //列表
    const tableIns = table.render({
        elem: '#list',
        url: $.cookie("tempUrl") + 'hOmsOrderServicePack/selectListByDoctorId',
        where: {
            doctorId: $.cookie("doctorId"),
        },
        method: "GET",
        request: {
            pageName: 'pageNum' //页码的参数名称，默认：page
            , limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            , statusCode: 200 //成功的状态码，默认：0
            , msgName: 'msg' //状态信息的字段名称，默认：msg
            , countName: 'totalElements' //数据总数的字段名称，默认：count
            , dataName: 'data' //数据列表的字段名称，默认：data
        },
        cellMinWidth: 95,
        page: true,
        height: "full-25",
        limits: [5, 10, 15, 20, 25],
        limit: 15,
        id: "dataTable",
        toolbar: '#toolbarDemo',
        defaultToolbar: ['filter', 'exports'],
        cols: [[
            {field: 'id', title: '订单编号', minWidth: 90, align: 'center'},
            {field: 'memberName', title: '患者姓名', minWidth: 100, align: 'center'},
            {
                title: '订单类型', minWidth: 100, align: "center", templet: function (d) {
                    return "服务包订单"
                }
            },
            {
                title: '订单时间', minWidth: 200, align: "center", templet: function (d) {
                    return d.createTime;
                }
            },
            {
                title: '订单状态', minWidth: 100, align: 'center', templet: function (d) {
                    switch (d.stat) {
                        case 1:
                            return "已支付";
                        case 2:
                            return "已退款";
                        case 3:
                            return "未支付";
                    }
                }
            },
            {
                title: '操作', width: 100, align: 'center', templet: function (d) {
                    return '<button class="layui-btn layui-btn-xs layui-btn-normal layui-disabled" id=' + d.id + ' lay-event="look" disabled>查看</button>';
                }
            },
            // {title: '操作', width: 90, templet: '#userListBar', fixed: "right", align: "center"}
        ]],
        done: function (res, curr, count) {
            //请选择开始日期
            laydate.render({
                elem: '.startDay',
                format: 'yyyy-MM-dd',
                trigger: 'click',
                max: 0,
                mark: {"0-1-1": "元旦"},
                done: function (value, date) {
                    if (date.month === 1 && date.date === 1) { //点击每年12月15日，弹出提示语
                        layer.msg('今天是元旦，新年快乐！');
                    }
                }
            });
            //请选择截止日期
            laydate.render({
                elem: '.endDay',
                format: 'yyyy-MM-dd',
                trigger: 'click',
                max: 0,
                mark: {"0-1-1": "元旦"},
                done: function (value, date) {
                    if (date.month === 1 && date.date === 1) { //点击每年12月15日，弹出提示语
                        layer.msg('今天是元旦，新年快乐！');
                    }
                }
            });
        }
    });

    //头工具栏事件
    table.on('toolbar(test)', function (obj) {
        const checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
            case 'search_btn':
                var startDay = $(".startDay").val();
                var endDay = $(".endDay").val();
                if (endDay === null || endDay === "") {
                    endDay = "2099-12-12"
                }
                var stat = $(".stat").val();
                table.reload("dataTable", {
                    url: $.cookie("tempUrl") + 'hOmsOrderServicePack/selectListByLike',
                    where: {
                        doctorId: $.cookie("doctorId"),
                        startDay: startDay,
                        endDay: endDay,
                        stat: stat,
                    }
                });
                //请选择开始日期
                laydate.render({
                    elem: '.startDay',
                    format: 'yyyy-MM-dd',
                    trigger: 'click',
                    max: 0,
                    mark: {"0-1-1": "元旦"},
                    done: function (value, date) {
                        if (date.month === 1 && date.date === 1) { //点击每年12月15日，弹出提示语
                            layer.msg('今天是元旦，新年快乐！');
                        }
                    }
                });
                //请选择截止日期
                laydate.render({
                    elem: '.endDay',
                    format: 'yyyy-MM-dd',
                    trigger: 'click',
                    max: 0,
                    mark: {"0-1-1": "元旦"},
                    done: function (value, date) {
                        if (date.month === 1 && date.date === 1) { //点击每年12月15日，弹出提示语
                            layer.msg('今天是元旦，新年快乐！');
                        }
                    }
                });
                $(".startDay").val(startDay)
                $(".endDay").val(endDay)
                $(".stat").val(stat)
                form.render();
                break;
        }
    });

    //列表操作
    table.on('tool(test)', function (obj) {
        const layEvent = obj.event,
            data = obj.data;
        let index;
        switch (layEvent) {
            case 'look'://查看详情
                index = layui.layer.open({
                    title: "服务包订单详情",
                    type: 2,
                    area: ["600px", "500px"],
                    content: "query05Info.html",
                    shadeClose: true,
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.find(".id").val(data.id);
                        form.render();
                        // setTimeout(function () {
                        //     layui.layer.tips('点击此处最大化', '.layui-layer-max', {
                        //         tips: 3
                        //     });
                        // }, 100)
                    }
                });
                break;
        }
    });
});
